package top.melody.ecommerce.webapps.console.base;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: blentle
 * @group: rd
 * @createdate: 2016/10/26 14:36
 * @mail: blentle.huan.ren@gmail.com
 * @description:
 * @since:1.0
 */
public class AssertContext {

    public static SecurityUserSession getCurrentSecurityUser(HttpServletRequest request) {
        SecurityUserSession userSession = (SecurityUserSession)request.getSession(true).getAttribute(Constant.CURRENT_USER_SESSION_ID);
        return userSession;
    }

    public static void putSecurityUser2Session(SecurityUserSession securityUser, HttpServletRequest request) {
        request.getSession().setAttribute(Constant.CURRENT_USER_SESSION_ID, securityUser);
    }

    public static void removeSecurityFromSession(String sessionKey, HttpServletRequest request) {
        request.getSession().removeAttribute(sessionKey);
    }

    public static String getContextPath(HttpServletRequest request) {
        return request.getContextPath();
    }
}
